package com.zyong.design.pattern.interpret.case2;

/**
 * 常量表达式
 * @program: zyong-design-pattern
 * @ClassName: Constant
 * @author: zyong
 * @create: 2024-06-01 22:01
 */
public class Constant extends Expression {
    private boolean value;

    public Constant(boolean value) {
        this.value = value;
    }

    @Override
    public boolean interpret(Context ctx) {
        return this.value;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj != null && obj instanceof Constant) {
            return this.value == ((Constant) obj).value;
        }

        return false;
    }

    @Override
    public int hashCode() {
        return this.toString().hashCode();
    }

    @Override
    public String toString() {
        return new Boolean(this.value).toString();
    }
}
